Skip to content

Document check_white, optical_density and rgb_yxc as stable API (P2 of the H&E tissue mask) - #108

Merged
guijacquemet merged 1 commit into
mainfrom
docs/stable-od-api
Nov 16, 2026
Merged

guijacquemet merged 1 commit into
mainfrom
docs/stable-od-api

Conversation

@guijacquemet

Copy link
Copy Markdown
Contributor

Prerequisite P2 of preprocessing's H&E tissue-mask helper (I1): morphobricks-preprocessing docs/design/he-tissue-mask.md at ce650e3, §9 P2 and owner decision Q5. Documentation and tests only, based on main 9616e12.

What changes

  • docs/contract.md §3.6 (new), "Stable optical-density helpers for other bricks", plus a pointer from §3.4 and a row in the implementation table. For each of

    • optical_density.optical_density(rgb: np.ndarray, white: np.ndarray) -> tuple[np.ndarray, float]
    • optical_density.check_white(white: object) -> np.ndarray
    • scalar_inputs.rgb_yxc(pixels: np.ndarray, axes: str) -> np.ndarray

    it gives the exact signature, the meaning, units and dtypes of each argument, and the return value. optical_density returns the pair (od, floored_fraction): od is a new float64 (Y, X, 3) array, -log10(max(I, 1) / white), with the floor FLOOR = 1.0; floored_fraction is a Python float. check_white returns a new float64 (3,). rgb_yxc returns a new C-contiguous uint8 (Y, X, 3). The section also lists every refusal in the order it is tested, with its exception type and message text. None of these refusals has a code or a message constant, and the section says so: they are programming-error refusals, so consumers match on the type. optical_density has no refusals of its own; its preconditions are the outputs of the other two functions.

  • What "stable" means: the import paths, signatures, return types, dtypes and shapes, the formula and floor, and the refusals are all part of the contract. Changing any of them needs the owner's approval and a plan §12 entry, and ships as a Breaking release (a minor-version bump before 1.0).

  • Namespace: no code change. The functions are already public module attributes, and they stay that way, as the §3.4/§3.5 modules do. A root re-export of the function optical_density would shadow the module morphobricks_normalization.optical_density, so the stable import paths are the module paths. These are the paths the design records.

  • tests/test_stable_od_api.py (22 tests) pins:

    • the module paths;
    • the inspect.signature of each function (parameter names, kinds, no defaults, annotations);
    • that none of the three is in the root __all__;
    • one behaviour each, including the tuple return of optical_density with od float64 (Y, X, 3) and a float fraction;
    • the exception type and message start of every refusal.
  • CHANGELOG ## Unreleased entry.

Identity

No file under src/ or tests/data/ changes, so the parity tests and goldens stay byte-identical.

Gate

python tools/check.py with PYTEST_ADDOPTS unset passes (exit 0): ruff format, code rules and ruff check clean; 2740 passed, 2 skipped. Both skips are tests/test_rgb.py:82, the optional csbdeep check, which is not installed.


Generated by Claude Code

New contract §3.6: the three optical-density helpers preprocessing's H&E
tissue mask calls are stable public API, with their signatures, units,
dtypes, the floor, the (od, floored_fraction) pair, every refusal in order
and what "stable" means. They stay module attributes (a root re-export of
optical_density would shadow its module). tests/test_stable_od_api.py pins
the import paths, signatures, one behaviour each and the refusal types.
No code or output change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G3qp9AxjpGPw9xfWAUJNqc
@guijacquemet
guijacquemet merged commit 30992e9 into main Nov 16, 2026
10 checks passed
@guijacquemet
guijacquemet deleted the docs/stable-od-api branch November 16, 2026 22:50
@guijacquemet guijacquemet mentioned this pull request Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants